home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Includes / UPrinting.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  49.9 KB  |  1,349 lines  |  [TEXT/MPS ]

  1. // UPrinting.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UPRINTING__
  5. #define __UPRINTING__
  6.  
  7. // MacApp
  8.  
  9. #ifndef __UCOMMAND__
  10. #include "UCommand.h"
  11. #endif
  12.  
  13. #ifndef __UFAILURE__
  14. #include "UFailure.h"
  15. #endif
  16.  
  17. #ifndef __UGEOMETRY__
  18. #include "UGeometry.h"
  19. #endif
  20.  
  21. #ifndef __UPRINTHANDLER__
  22. #include "UPrintHandler.h"
  23. #endif
  24.  
  25. // Toolbox
  26.  
  27. #ifndef __DIALOGS__
  28. #include <Dialogs.h>
  29. #endif
  30.  
  31. // ANSI
  32.  
  33. #ifndef __LIMITS__
  34. #include <limits.h>
  35. #endif
  36.  
  37.  
  38. //----------------------------------------------------------------------------------------
  39. //  Constants for the print info resources
  40. //----------------------------------------------------------------------------------------
  41.  
  42. const ResType    kGXPrintInfoRsrcType = 'FJOB';
  43. const ResNumber    kGXPrintInfoRsrcID = 128;
  44.  
  45. const ResType    kPrintInfoRsrcType = 'PREC';
  46. const ResNumber    kPrintInfoRsrcID = 128;
  47.  
  48. const ResType    kAlternatePrintInfoRsrcType = 'PRNT';
  49. const ResNumber    kAlternatePrintInfoRsrcID = 128;
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // Forward and external class declarations. 
  53. //----------------------------------------------------------------------------------------
  54.  
  55. class TDocument;
  56. class TView;
  57. class TPrintInfo;
  58.  
  59. //----------------------------------------------------------------------------------------
  60. // Forward and external structures and pointers. 
  61. //----------------------------------------------------------------------------------------
  62. //
  63. // These keep us from having to include any of the printing interfaces in our interface
  64. // Since these are blind pointers they should not ever have to change much
  65. //
  66. #if qGXPrinting
  67. struct gxPrivateJobRecord;
  68. typedef struct gxPrivateJobRecord *gxJob;
  69. #endif
  70.  
  71. struct TPrint;
  72. typedef struct TPrint TPrint, *TPPrint, **THPrint;
  73.  
  74. struct TPrPort;
  75. typedef struct TPrPort TPrPort, *TPPrPort;
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // Command constants: Printing-related command numbers which apply only when a view with a
  79. // non-NULL PrintHandler is in the target chain
  80. //----------------------------------------------------------------------------------------
  81.  
  82. const CommandNumber cChangePrinterStyle = 192;        // Command arising from user's making
  83.                                                     // changes in Page Setup... dialog
  84.  
  85. const CommandNumber cShowBreaks = 201;                // Show Page Breaks command
  86.  
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // Alert rsrc IDs
  90. //----------------------------------------------------------------------------------------
  91.  
  92. const ResNumber phSpoolPrintDialog = 257;        // the dialog shown when printing a file
  93.                                                 // (a misnomer - not just when spooled)
  94.  
  95. const ResNumber phFinderPrintDialog = 258;        // the dialog shown when doing Finder
  96.                                                 // Printing; differs from prev. by
  97.                                                 // addition of a 'Cancel All Printing'
  98.                                                 // button
  99.  
  100. const ResNumber phNoPages = 251;                // The "No pages within requested range"
  101.                                                 // alert
  102.  
  103. //----------------------------------------------------------------------------------------
  104. // Dialog rsrc IDs
  105. //----------------------------------------------------------------------------------------
  106.  
  107. const ResNumber phWhichDoc = 261;                // The "Preparing to print <docname>"
  108.                                                 // dialog used during Finder printing
  109.  
  110.  
  111. //----------------------------------------------------------------------------------------
  112. // Miscellaneous
  113. //----------------------------------------------------------------------------------------
  114.  
  115. const short kUsualPages = SHRT_MAX;                // For methods that take a pageNumber
  116.                                                 // argument, this value indicates a
  117.                                                 // request for a general setting rather
  118.                                                 // than a setting customized to one
  119.                                                 // particular page
  120.  
  121. const ResNumber kPrintDriverName = -8192;        // STR resource in System file which
  122.                                                 // contains name of the default printer
  123.  
  124.  
  125.  
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // Common Ancestor for printjob objects from different print architectures (MacPrint, GX, etc)
  129. //----------------------------------------------------------------------------------------
  130.  
  131. class TPrintInfo : public TObject
  132. {
  133.     MA_DECLARE_CLASS;
  134.     
  135. public:
  136.     TPrintInfo();
  137.     
  138.     virtual ~TPrintInfo();
  139.     
  140.     void IPrintInfo();
  141.  
  142.     virtual TObject* Clone();
  143.         // Makes a copy of the printInfo
  144.  
  145.     virtual void ReadFrom(TStream* aStream);
  146.         // Read the fHPrint from the stream
  147.  
  148.     virtual void SetFrom(TPrintInfo* jobToCopy);
  149.         // copy settings from another job
  150.  
  151.     virtual long GetSize(Boolean asResource = TRUE);
  152.         // return the number of bytes necessary to store the print handle
  153.         // asResource lets you make a distinction in the storage type
  154.  
  155.     virtual void DoUpdate(ChangeID theChange,
  156.                   TObject* changedObject,
  157.                   TObject* changedBy,
  158.                   TDependencySpace* dependencySpace);    // Override
  159.         // If the printer has changed then we're invalid
  160.  
  161.     virtual VRect GetPaperRect();
  162.         // returns the paper's rect
  163.  
  164.     virtual VRect GetInkRect();
  165.         // returns the imagable page's rect
  166.  
  167.     virtual CPoint GetDeviceRes();
  168.         // returns the current device's resolution vertically and horizontally
  169.  
  170.     virtual void SetToDefault();
  171.         // Set the print Info to the default state
  172.  
  173.     virtual Boolean IsSetToDefault();
  174.         // Returns TRUE if this Matches the printer's default
  175.  
  176.     virtual void GetPrintPages(long& fromPage,
  177.                                long& toPage,
  178.                                long& minFromPage,
  179.                                long& maxToPage);
  180.         // Returns the page range of the job to print
  181.  
  182.     virtual void SetPrintPages(long fromPage,
  183.                                long toPage,
  184.                                long minFromPage,
  185.                                long maxToPage);
  186.         // Sets the page range of the job to print
  187.  
  188.     virtual long GetPrintCopies();
  189.         // Returns the number of copies specified in the job
  190.  
  191.     virtual void SetPrintCopies(long numCopies);
  192.         // Sets the number of copies specified in the job
  193.  
  194.     virtual void SetTargetPrinter(const FSSpec& targetPrinter);
  195.         // Sets the target printer for a "drag print"
  196.  
  197.     virtual void SetSpoolFile(FSSpec& spoolFile);
  198.         // Sets the location for the spool file
  199.  
  200.     virtual Boolean IsSpooling();
  201.         // Returns TRUE if we are spooling and not just drafting straight to the printer
  202.  
  203.     virtual Boolean IsMatch(TPrintInfo* thePrintInfo);
  204.         // Returns TRUE if thePrintInfo can be said to match. FALSE if they
  205.         // don't match or it can't be determined without validating them.
  206.         // thePrintInfo doesn't have to be Valid but 'this' must be Valid
  207.         // if it is not waiting for a default call
  208.  
  209.     virtual void Open(TObject* byWhom = NULL);
  210.         // Attempts to open the printer. Signals failure if an error occurs.
  211.  
  212.     virtual Boolean IsOpen();
  213.         // Returns TRUE if the printer is open.
  214.  
  215.     virtual void Close(TObject* byWhom = NULL);
  216.         // Closes the Printer. DOES NOT signal failure if an error
  217.         // occurs, only reports it to the debug window.
  218.  
  219.     Boolean IsDefaultForPrinter(TPrintInfo* thePrintInfo);
  220.         // Returns TRUE if thePrintInfo matches the default for this printer.
  221.  
  222.     virtual OSErr GetError();
  223.         // Return any current printing error.
  224.  
  225.     virtual void SetError(OSErr err);
  226.         // Set the current printing error.
  227.  
  228.     virtual void ClearError();
  229.         // Clear any current printing error.
  230.  
  231.     virtual Boolean ChkPrintErr(OSErr& err,
  232.                                           Boolean& ranOutOfSpace);
  233.  
  234.     virtual void StartJob(const CStr255&             ,
  235.                          long                    );
  236.         // Start a printing job.
  237.  
  238.     virtual GrafPtr GetJobPort();
  239.         // Returns the port that the job is printing to
  240.  
  241.     virtual void FinishJob();
  242.         // Completes a printing job.
  243.  
  244.     virtual void StartPage(long                    );
  245.         // Start a page.
  246.  
  247.     virtual void FinishPage();
  248.         // Finish a page.
  249.  
  250.     virtual void JobMerge(TPrintInfo* mergeFrom);
  251.         // Validate and Merge the job info from the source job onto the
  252.         // destination job and Validate the result
  253.  
  254.     virtual TPrintInfo* GetDefaultPrintInfo();
  255.         // Returns THE default TPrintInfo. Creating it first, if neccessary
  256.         
  257.     virtual Boolean CallJobDialog();
  258.         // Calls PrJobDialog.
  259.         
  260.     virtual Boolean CallStyleDialog();
  261.         // Calls PrStlDialog.
  262.         
  263.     virtual Boolean CallPrValidate();
  264.         // Validates the printInfo.
  265.         
  266.     virtual void CallPrintDefault();
  267.         // Calls PrintDefault.
  268.  
  269.     virtual Boolean CallPrPicFile(OSErr& err);
  270.         // Calls PrPicFile.
  271.  
  272.     virtual void Invalidate();
  273.         // Mark as invalid and issue a changed message
  274.  
  275.     virtual void Update();
  276.         // Check if the target printer has changed and inform dependents if necessary
  277.         // Ensures that the print info is current and valid
  278.  
  279.     void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
  280.         // Return the maximum square resolution supported by the printer
  281.  
  282.     void SetResolution(Fixed hRes, Fixed vRes);
  283.         // Sets the printer to use the supplied resolution
  284.  
  285.     void MaximizeResolution();
  286.         // Sets the printer to use the maximum square resolution
  287.  
  288.     inline Boolean IsValid()
  289.     { return fIsValid; }
  290.         // return the fIsValid flag
  291.  
  292.     inline Boolean NeedsDefault()
  293.     { return fNeedsDefault; }
  294.         // return the fNeedsDefault flag
  295.  
  296.     virtual void PosePrintDialog(const CStr255& docName, CommandNumber aCommandNumber);
  297.         // Put up the 'Printing in Progress' dialog ( if applicable )
  298.  
  299.     virtual void BanishPrintDialog();
  300.         // Get rid of the print dialog.
  301.  
  302.     virtual void ShowDocBeingPrinted(const CStr255& docName, Boolean entering);
  303.         // Put up (or remove) a window whose title is the document's title, because the
  304.         // Print Manager gets the document title from the front window.
  305.  
  306.     //----------------------------------------------------------------------------------------
  307.     // data members
  308.     //----------------------------------------------------------------------------------------
  309. protected:
  310.     Boolean    fIsValid;                    // true if the print record is valid
  311.                                         // because it's been validated OR
  312.                                         // is the result of a setup dialog or sumthin'.
  313.     Boolean    fNeedsDefault;                // true if the print record is valid
  314. };
  315.  
  316.  
  317. #if qGXPrinting
  318. //----------------------------------------------------------------------------------------
  319. // Encapsulates the the gxJob, etc for GX printing
  320. //----------------------------------------------------------------------------------------
  321.  
  322. struct MySpoolDataRec
  323. {
  324.     gxRectangle pageArea;                    // Page rectangle.
  325.     gxViewPort printViewPort;                // ViewPort we're printing with.
  326. };
  327.  
  328. class TGXJob : public TPrintInfo
  329. {
  330.     MA_DECLARE_CLASS;
  331.     
  332. public:
  333.  
  334.     TGXJob();
  335.     
  336.     virtual ~TGXJob();
  337.     
  338.     void IGXJob(gxJob itsgxJob=NULL, Boolean isValid=FALSE);
  339.         // If itsgxJob is NULL the default job is retrieved from itsPrintMgr.
  340.         // If itsPrintMgr is NULL the gDefaultPrinter will be used.
  341.  
  342.     virtual TObject* Clone();
  343.         // Makes a copy of the printInfo
  344.  
  345.     virtual void ReadFrom(TStream* aStream);
  346.         // Read the gxJob from the stream
  347.  
  348.     virtual void ConvertFrom(TStream* aStream);
  349.         // Read the THPrint from the stream
  350.  
  351.     virtual void WriteTo(TStream* aStream);
  352.         // Write the fHPrint to the stream
  353.  
  354.     virtual void SetFrom(TPrintInfo* jobToCopy);
  355.         // copy settings from another job
  356.  
  357.     void SetFrom(gxJob jobToCopy, Boolean isValid = FALSE,
  358.                 Boolean needsDefault = FALSE);
  359.         // copy settings from another gxJob
  360.         // set IsValid TRUE if the handle is known to be valid
  361.  
  362.     virtual long GetSize(Boolean asResource = TRUE);
  363.         // return the number of bytes necessary to store the print handle
  364.         // asResource lets you make a distinction in the storage type
  365.  
  366.     static pascal OSErr GetSizeHelper (long size, void *data, void *refCon);
  367.         // Helps the GetSize function by counting the number of bytes in GXFlattenJob
  368.  
  369.     virtual VRect GetPaperRect();
  370.         // returns the paper's rect
  371.  
  372.     virtual VRect GetInkRect();
  373.         // returns the imagable page's rect
  374.  
  375.     virtual CPoint GetDeviceRes();
  376.         // returns the current device's resolution vertically and horizontally
  377.  
  378.     virtual void SetToDefault();
  379.         // Set the print Info to the default state
  380.  
  381.     virtual Boolean IsSetToDefault();
  382.         // Returns TRUE if this Matches the printer's default
  383.  
  384.     virtual void GetPrintPages(long& fromPage,
  385.                                long& toPage,
  386.                                long& minFromPage,
  387.                                long& maxToPage);
  388.         // Returns the page range of the job to print
  389.  
  390.     virtual void SetPrintPages(long fromPage,
  391.                                long toPage,
  392.                                long minFromPage,
  393.                                long maxToPage);
  394.         // Sets the page range of the job to print
  395.  
  396.     virtual long GetPrintCopies();
  397.         // Returns the number of copies specified in the job
  398.  
  399.     virtual void SetPrintCopies(long numCopies);
  400.         // Sets the number of copies specified in the job
  401.  
  402.     virtual void SetTargetPrinter(const FSSpec& targetPrinter);
  403.         // Sets the target printer for a "drag print"
  404.  
  405.     Boolean IsDefaultForPrinter(TPrintInfo* thePrintInfo);
  406.         // Returns TRUE if thePrintInfo matches the default for this printer.
  407.  
  408.     virtual OSErr GetError();
  409.         // Return any current printing error.
  410.  
  411.     virtual void SetError(OSErr err);
  412.         // Set the current printing error.
  413.  
  414.     virtual void StartJob(const CStr255&             ,
  415.                         long                    );
  416.         // Start a printing job.
  417.  
  418.     virtual GrafPtr GetJobPort();
  419.         // Returns the port that the job is printing to
  420.  
  421.     virtual void FinishJob();
  422.         // Completes a printing job.
  423.  
  424.     virtual void StartPage(long                    );
  425.         // Start a page.
  426.  
  427.     virtual void FinishPage();
  428.         // Finish a page.
  429.  
  430.     virtual void JobMerge(TPrintInfo* mergeFrom);
  431.         // Validate and Merge the job info from the source job onto the
  432.         // destination job and Validate the result
  433.  
  434.     virtual Boolean CallJobDialog();
  435.         // Calls the job dialog.
  436.         
  437.     virtual Boolean CallStyleDialog();
  438.         // Calls the setup dialog.
  439.         
  440.     virtual Boolean CallPrValidate();
  441.         // Validates the printInfo.
  442.         
  443.     virtual void CallPrintDefault();
  444.         // Calls PrintDefault.
  445.  
  446.     virtual void Update();
  447.         // Check if the target printer has changed and inform dependents if necessary
  448.         // Ensures that the print info is current and valid
  449.  
  450.     virtual void DoUpdate(ChangeID theChange,
  451.                   TObject* changedObject,
  452.                   TObject* changedBy,
  453.                   TDependencySpace* dependencySpace);    // Override
  454.         // Check for printer driver changes on mAboutToLoseContro/mRegainControl
  455.  
  456.     void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
  457.         // Return the maximum square resolution supported by the printer
  458.  
  459.     void SetResolution(Fixed hRes, Fixed vRes);
  460.         // Sets the printer to use the supplied resolution
  461.  
  462. protected:
  463.     gxJob GetgxJob();
  464.         // Returns the fgxJob after Validation
  465.  
  466.     gxJob GetRawgxJob();
  467.         // Returns the fgxJob without Validation
  468.  
  469.     void AdoptJob(gxJob itsgxJob);
  470.         // call to adopt a job that's new to this info
  471.  
  472.     //----------------------------------------------------------------------------------------
  473.     // static member functions
  474.     //----------------------------------------------------------------------------------------
  475. protected:
  476.  
  477. // These "C++" calling convention routines will be called via UPPs
  478. #if defined(__MWERKS__) && !(__POWERPC__ || __CFM68K__)
  479. #    pragma d0_pointers on
  480. #endif
  481.     static OSErr PrintingEventOverride(EventRecord* anEvent, Boolean filterEvent);
  482.  
  483.     static OSErr MyPrintAShape(gxShape currentShape, long refCon);
  484.         // MyPrintAShape - This is a spool proc. for the translator
  485.         // routines. In this routine, we simply draw each shape
  486.         // we're passed (printing it).  You could also capture each
  487.         // shape into one gxPicture shape, and then do one draw of
  488.         // that afterwards.
  489. #if defined(__MWERKS__) && !(__POWERPC__ || __CFM68K__)
  490. #    pragma d0_pointers reset
  491. #endif
  492.  
  493.     static pascal OSErr MyUnflattenFunction(long size, void *data, void *refCon);
  494.         // MyUnflattenFunction - This proc will get called when unflattening
  495.         // a gxjob.
  496.  
  497.     static pascal OSErr MyFlattenFunction(long size, void *data, void *refCon);
  498.         // MyFlattenFunction - This proc will get called when flattening
  499.         // a gxjob.
  500.  
  501.  
  502.     //----------------------------------------------------------------------------------------
  503.     // data members
  504.     //----------------------------------------------------------------------------------------
  505. protected:
  506.     gxJob    fgxJob;                        // Default, validated job
  507.     gxViewPort fPrintViewPort;            // ViewPort for printing
  508.  
  509.     CGrafPort fQDPortRec;                // Printer Port in use during printing
  510.     CGrafPtr fQDPort;                    // Printer Port in use during printing
  511.     MySpoolDataRec fSpoolData;            // area to pass stuff to the PrintAShape routine
  512. };
  513. #endif
  514.  
  515.  
  516. //----------------------------------------------------------------------------------------
  517. // Encapsulates the THPrint for MacPrint printing
  518. //----------------------------------------------------------------------------------------
  519.  
  520.  
  521. //----------------------------------------------------------------------------------------
  522. // Manage entrance and exit from MacPrint
  523. //----------------------------------------------------------------------------------------
  524.  
  525. class CInMacPrint
  526. {
  527. protected:
  528.     void* operator new(size_t size);            // prohibit "new CInMacPrint"
  529.     void operator delete(void* obj);            // avoid compiler warnings
  530.     
  531. public:
  532.     CInMacPrint(TPrintInfo* itsPrintinfo = NULL, TObject* byWhom = NULL, Boolean active=TRUE);
  533.     // Puts us in the context of MacPrint.
  534.     // if itsPrintMgr is NULL use the gDefaultPrinter
  535.     // if byWhom is NULL use itsPrintMgr
  536.     // If active is FALSE, nothing happens.
  537.  
  538.     ~CInMacPrint();
  539.     // Removes the MacPrint context removes the failure handler.
  540.  
  541.     void Cleanup();
  542.     
  543.     //----------------------------------------------------------------------------------------
  544.     // static member functions
  545.     //----------------------------------------------------------------------------------------
  546.     static void CallCleanup(void* context);
  547.     
  548.     //----------------------------------------------------------------------------------------
  549.     // data members
  550.     //----------------------------------------------------------------------------------------
  551. protected:
  552.     FailInfo    fFailInfo;                        // the failure record that references
  553.                                                 // the failure handling method
  554.     TPrintInfo*    fPrintInfo;                        // The TPrintInfo used by us
  555.     TObject*    fByWhom;                        // the object responsible for this
  556.     short        fResFile;                        // The CurResFile before opening the print shop
  557.     Boolean        fIsActive;                        // True if we are going to activate.
  558.     Boolean        fPrintShopOpened;                // True if the print shoppe opened successfully
  559. };
  560.  
  561.  
  562. class TMacPrintJob : public TPrintInfo
  563. {
  564.     MA_DECLARE_CLASS;
  565.     
  566. public:
  567.  
  568.     TMacPrintJob();
  569.     
  570.     virtual ~TMacPrintJob();
  571.     
  572.     void IMacPrintJob(THPrint itsHPrint = NULL, Boolean isValid = FALSE);
  573.         // If itsHPrint is NULL the default HPrint is retrieved from gDefaultPrintMgr
  574.  
  575.     virtual TObject* Clone();
  576.         // Makes a copy of the printInfo
  577.  
  578.     virtual void ReadFrom(TStream* aStream);
  579.         // Read the fHPrint from the stream
  580.  
  581.     virtual void WriteTo(TStream* aStream);
  582.         // Write the fHPrint to the stream
  583.  
  584.     virtual void SetFrom(TPrintInfo* jobToCopy);
  585.         // copy settings from another job
  586.  
  587.     void SetFrom(THPrint hPrintToCopy, Boolean isValid = FALSE,
  588.                 Boolean needsDefault = FALSE);
  589.         // copy settings from another THPrint
  590.         // set IsValid TRUE if the handle is known to be valid
  591.  
  592.     virtual long GetSize(Boolean asResource = TRUE);
  593.         // return the number of bytes necessary to store the print handle
  594.         // asResource lets you make a distinction in the storage type
  595.  
  596.     virtual VRect GetPaperRect();
  597.         // returns the paper's rect
  598.  
  599.     virtual VRect GetInkRect();
  600.         // returns the imagable page's rect
  601.  
  602.     virtual CPoint GetDeviceRes();
  603.         // returns the current device's resolution vertically and horizontally
  604.  
  605.     virtual void SetToDefault();
  606.         // Set the print Info to the default state
  607.  
  608.     virtual Boolean IsSetToDefault();
  609.         // Returns TRUE if this Matches the printer's default
  610.  
  611.     virtual void GetPrintPages(long& fromPage,
  612.                                long& toPage,
  613.                                long& minFromPage,
  614.                                long& maxToPage);
  615.         // Returns the page range of the job to print
  616.  
  617.     virtual void SetPrintPages(long fromPage,
  618.                                long toPage,
  619.                                long minFromPage,
  620.                                long maxToPage);
  621.         // Sets the page range of the job to print
  622.  
  623.     virtual long GetPrintCopies();
  624.         // Returns the number of copies specified in the job
  625.  
  626.     virtual void SetPrintCopies(long numCopies);
  627.         // Sets the number of copies specified in the job
  628.  
  629.     virtual void SetSpoolFile(FSSpec& spoolFile);
  630.         // Sets the location for the spool file
  631.  
  632.     virtual Boolean IsSpooling();
  633.         // Returns TRUE if we are spooling and not just drafting straight to the printer
  634.  
  635.     virtual Boolean IsMatch(TPrintInfo* thePrintInfo);
  636.         // Returns TRUE if thePrintInfo can be said to match. FALSE if they
  637.         // don't match or it can't be determined without validating them.
  638.         // thePrintInfo doesn't have to be Valid but 'this' must be Valid
  639.         // if it is not waiting for a default call
  640.  
  641.     virtual void Open(TObject* byWhom = NULL);
  642.         // Attempts to open the printer. Signals failure if an error occurs.
  643.  
  644.     virtual Boolean IsOpen();
  645.         // Returns TRUE if the printer is open.
  646.  
  647.     virtual void Close(TObject* byWhom = NULL);
  648.         // Closes the Printer. DOES NOT signal failure if an error
  649.         // occurs, only reports it to the debug window.
  650.  
  651.     virtual OSErr GetError();
  652.         // Return any current printing error.
  653.  
  654.     virtual void SetError(OSErr err);
  655.         // Set the current printing error.
  656.  
  657.     virtual void StartJob(const CStr255&             ,
  658.                          long                    );
  659.         // Start a printing job.
  660.  
  661.     virtual GrafPtr GetJobPort();
  662.         // Returns the port that the job is printing to
  663.  
  664.     virtual void FinishJob();
  665.         // Completes a printing job.
  666.  
  667.     virtual void StartPage(long                    );
  668.         // Start a page.
  669.  
  670.     virtual void FinishPage();
  671.         // Finish a page.
  672.  
  673.     virtual void JobMerge(TPrintInfo* mergeFrom);
  674.         // Validate and Merge the job info from the source job onto the
  675.         // destination job and Validate the result
  676.  
  677.     virtual Boolean CallJobDialog();
  678.         // Calls the job dialog.
  679.         
  680.     virtual Boolean CallStyleDialog();
  681.         // Calls the setup dialog.
  682.         
  683.     virtual Boolean CallPrValidate();
  684.         // Validates the printInfo.
  685.         
  686.     virtual void CallPrintDefault();
  687.         // Calls PrintDefault.
  688.  
  689.     virtual Boolean CallPrPicFile(OSErr& err);
  690.         // Calls PrPicFile.
  691.  
  692.     virtual void Update();
  693.         // Check if the target printer has changed and inform dependents if necessary
  694.         // Ensures that the print info is current and valid
  695.  
  696.     virtual void DoUpdate(ChangeID theChange,
  697.                   TObject* changedObject,
  698.                   TObject* changedBy,
  699.                   TDependencySpace* dependencySpace);    // Override
  700.         // Check for printer driver changes on mAboutToLoseContro/mRegainControl
  701.  
  702.     void GetMaxSquareResolution(Fixed& hRes, Fixed& vRes);
  703.         // Return the maximum square resolution supported by the printer
  704.  
  705.     void SetResolution(Fixed hRes, Fixed vRes);
  706.         // Sets the printer to use the supplied resolution
  707.  
  708.     void MaximizeResolution();
  709.         // Sets the printer to use the maximum square resolution
  710.  
  711.     virtual void DoPrintIdling();
  712.         // Print job idle time handler. Handles events in the 'Print Dialogs' which give
  713.         // the user 'Cancel', and, in the case of printing from the Finder, 'Cancel All
  714.         // Printing.'
  715.  
  716.     virtual void PosePrintDialog(const CStr255& docName, CommandNumber aCommandNumber);
  717.         // Put up the 'Printing in Progress' dialog ( if applicable )
  718.  
  719.     virtual void BanishPrintDialog();
  720.         // Get rid of the print dialog.
  721.  
  722.     virtual void ShowDocBeingPrinted(const CStr255& docName, Boolean entering);
  723.         // Put up (or remove) a window whose title is the document's title, because the
  724.         // Print Manager gets the document title from the front window.
  725.  
  726. protected:
  727.     THPrint GetHPrint();
  728.         // Returns the fHPrint after Validation
  729.  
  730.     THPrint GetRawHPrint();
  731.         // Returns the fHPrint without Validation
  732.  
  733.     //----------------------------------------------------------------------------------------
  734.     // static member functions
  735.     //----------------------------------------------------------------------------------------
  736. public:
  737.     static unsigned long CheckPrinterChangeLevel();
  738.         // Determine if the user has selected a new printer type from the chooser.
  739.  
  740.     static void GetDriverName(CStr255& driverName);
  741.         // Get the name of the current printer driver.
  742.  
  743.     static pascal void IdleProc();
  744.     // Procedure whose address is passed to the print job for calling as often as
  745.     // possible. Forwards to the DoPrintIdling method of the job's print handler.
  746.     // NOTE: this routine requires the pascal keyword because it is a Toolbox callback
  747.  
  748.     //----------------------------------------------------------------------------------------
  749.     // data members
  750.     //----------------------------------------------------------------------------------------
  751. protected:
  752.     CStr255 fCurrentDocTitle;            // Name of the current document being printed
  753.     DialogRef fPrintDialog;                        // Used for all printing-related dialogs.
  754.                                                 // ??? (shouldn't this really be a view
  755.                                                 // (or TDialogView if using UDialog)
  756.  
  757.     THPrint    fHPrint;                    // The THPrint for this job
  758.     long fMinFromPage;                        // The minimum page that can be printed (for this jobs document)
  759.     long fMaxToPage;                        // The maximum page that can be printed (for this jobs document)
  760.     
  761.     unsigned long fPrinterChangeLevel;  // increases every time the name change is noticed.
  762.  
  763.     static TPPrPort fQDPort;            // Printer Port in use during printing
  764.     static short fPrintShopOpens;        // counter for balancing Open and Close
  765.  
  766.     static CStr255 fgLastPrinterName;            // printer that we're pointing at
  767.     static unsigned long fgPrinterChangeLevel; // increases every time the name change is noticed.
  768. };
  769.  
  770.  
  771. //----------------------------------------------------------------------------------------
  772. // TStdPrintHandler: Actually Implements all the features that were stubbed out in its
  773. // ancestor. Basic flow of control at print time: Print, Validate, For each page(
  774. // FocusOnBorder, DrawPageInterior, FocusOnBorder, AdornPage) are called.
  775. //----------------------------------------------------------------------------------------
  776.  
  777. class TStdPrintHandler : public TPrintHandler
  778. {
  779.     MA_DECLARE_CLASS;
  780.     
  781. public:
  782.     //------------------------------------------------------------------------------------
  783.     // Initialization/ Termination
  784.     //------------------------------------------------------------------------------------
  785.  
  786.     TStdPrintHandler();
  787.         // Constructor
  788.         
  789.     void IStdPrintHandler(TDocument* itsDocument = NULL,
  790.                           TView* itsView = NULL,
  791.                           Boolean itsHFixedSize = kFixedSize,
  792.                           Boolean itsVFixedSize = kFixedSize);
  793.         // Initializes the printHandler and installs it in the view; 
  794.         // Uses the default TPrintInfo if itsPrintInfo is NULL
  795.         // By default the pages are considered fixed size.
  796.  
  797.     virtual ~TStdPrintHandler();
  798.         // If relevant, frees the PrintInfo record and does other cleanup before freeing
  799.         // this
  800.  
  801.     virtual TObject* Clone();    // Override
  802.         // calls Inherited::Clone and then clones owned objects
  803.  
  804.  
  805.     //------------------------------------------------------------------------------------
  806.     // Page Strips
  807.     //------------------------------------------------------------------------------------
  808.  
  809.     virtual VPoint CalcPageStrips();
  810.         // Recalculate the number of strips of pages in each dimension.
  811.  
  812.     virtual VPoint CalcViewPerPage();
  813.         // Decide how much view (h and v) normally gets mapped into page interiors.
  814.  
  815.     virtual VCoordinate BreakFollowing(VHSelect vhs,
  816.                                        VCoordinate previousBreak,
  817.                                        Boolean& automatic);
  818.         // Returns the location of the page break which follows the page break located at
  819.         // 'previousBreak', in direction vhs; returns automatic = true if the page-break is
  820.         // thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note
  821.         // that page-breaks in dimension 'v' are drawn as vertical lines, those in
  822.         // dimension 'h' as horizontal lines. Generic support at present is only provided
  823.         // for 'automatic' page breaks; the 'automatic' parameter in BreakFollowing is a
  824.         // hook to allow clients to support manual page breaks as well
  825.  
  826.     virtual void GetBreakCoord(VHSelect vhs,
  827.                                long whichBreak,
  828.                                VCoordinate& loc);
  829.         // Returns, in 'loc', the coordinate of the 'whichBreak-th' page break in
  830.         // dimension vhs. For example, GetBreakCoord(v, 5, loc) will return, in 'loc', the
  831.         // horizontal coordinate of the vertical line (page-break) which marks the
  832.         // boundary the area of the view which will be mapped into the 4th vertical strip
  833.         // of pages and the area of the view which will be mapped into the 5th vertical
  834.         // strip of pages
  835.  
  836.     virtual VPoint PageToStrip(long pageNumber);
  837.         // Returns the horizontal and vertical strip for the given page.
  838.  
  839.     virtual long StripToPage(VPoint pageStrip);
  840.         // Returns the page number for the given page strip.
  841.  
  842.  
  843.     //------------------------------------------------------------------------------------
  844.     // General Utility
  845.     //------------------------------------------------------------------------------------
  846.  
  847.     virtual CStr255 GetDocName();
  848.         // Returns the name of the document being printed, for use in the print dialog.
  849.  
  850.     virtual long MaxPageNumber();
  851.         // Returns the highest page number which would be printed if the user requested
  852.         // that all pages be printed.
  853.  
  854.     virtual void AdornPage();
  855.         // Draw things on page # 'aPageNumber' which do not arise from the View but rather
  856.         // from page considerations; examples: Headers and Footers; page numbers; frames
  857.         // drawn around inset text; row and column headers for spreadsheets.
  858.  
  859.     virtual void ChooseSpoolFile(FSSpec& theSpoolFile,
  860.                                  long& pagesPerSubjob);
  861.         // Select the filename and volume to use for spooling; default chooses empty
  862.         // CString on vol 0, which results in MacPrint's automatically choosing the local
  863.         // Boot volume
  864.  
  865.     virtual void DrawPageInterior();
  866.         // Make the QuickDraw calls which will result in the 'Interior' of page #
  867.         // 'aPageNumber' being drawn. The 'Interior' is those things on the page which
  868.         // arise from drawing the View associated with the PrintHandler
  869.  
  870.     virtual Boolean Focus();    // override
  871.         // Set up the GrafPort, clipping, etc., to its values prior to printing a view
  872.  
  873.     virtual void FocusOnBorder();
  874.         // Set up GrafPort, clipping, etc., prior to calling AdornPage
  875.  
  876.     virtual void FocusOnInterior();
  877.         // Set up the GrafPort, clipping, etc., prior to calling DrawPageInterior
  878.  
  879.     virtual long GetDefaultSubJobSize();
  880.         // Return default subjob size: SHRT_MAX
  881.  
  882.     virtual CPoint GetQDOrigin();    // override
  883.         // Overridden to return fQDOrigin.
  884.  
  885.     virtual VPoint GetViewToQDOffset();
  886.         // Overridden to return fViewToQDOffset.
  887.  
  888.     virtual VPoint LocatePageInterior(long pageNumber);
  889.         // Determine where to locate the top-left corner of the Interior of the given page
  890.         // number
  891.  
  892.     virtual Boolean OneSubJob(long subjobFirstPage,
  893.                                 long subjobLastPage,
  894.                                 long minFromPage,
  895.                                 long maxToPage,
  896.                                 Boolean justSpool,
  897.                                 Boolean partialJob,
  898.                                 Boolean& ranOutOfSpace,
  899.                                 long& lastPageTried);
  900.         // Processes one subjob for printing. Where appropriate, a print job is divided
  901.         // automatically into one or more 'subjobs', so that a long document can be
  902.         // printed even if there is very limited spool space available on the disk. This
  903.         // is a generalization of the 'spool-a-page/ print-a-page' technique.
  904.         // TStdPrintHandler will use a subjob size as large as can be handled by current
  905.         // conditions, and will only fall back to more subjobs, each of smaller size, if
  906.         // it experiences problems running with a larger subjob size
  907.         // Returns TRUE to proceed
  908.  
  909.     virtual Boolean Print(CommandNumber itsCommandNumber);
  910.         // Carries out printing for the print handler.
  911.         // Returns TRUE to proceed
  912.  
  913.     virtual void PrintPage(long aPageNumber);
  914.         // Print the indicated page
  915.  
  916.     virtual void SetPage(long aPageNumber);
  917.         // Forwards to TView::DoSetInterior and TView::DoSetPageOffset
  918.  
  919.     virtual void SetPageInterior(long pageNumber);
  920.         // Responsible for installing the correct values into fPageAreas.theInterior,
  921.         // representing the 'interior' of the page in View coordinates.
  922.  
  923.     virtual void SetPageOffset(const VPoint& coord);
  924.         // Given the view-coordinate of the top-left-most CPoint of the view which is
  925.         // mapped into the interior of this page, calculate and set the offset for the
  926.         // print code.
  927.  
  928.  
  929.     //------------------------------------------------------------------------------------
  930.     // Formatting for printing and other Setup methods
  931.     //------------------------------------------------------------------------------------
  932.  
  933.     virtual void Invalidate();
  934.         // Mark as invalid and issue a changed message
  935.  
  936.     virtual void Update();
  937.         // Recompute the projection model and notify views if it changed
  938.  
  939.     virtual void InstallMargins(const VRect& newMargins,
  940.                                 Boolean areMinimalMargins);
  941.         // Install the (possibly new) margins specified; if 'areMinimalMargins' is true,
  942.         // then the minimal-margins scheme is used; in this scheme, margins are always
  943.         // maintained at exactly the size necessary to have the page Interior coincide
  944.         // exactly with the printable area of the page
  945.  
  946.     virtual void MarginsTooBig(VRect &margins);
  947.         // called by InstallMargins if the passed-in margins are too big for the current paper.
  948.         // On entry, margins is the bad margins, on exit are (presumably) good margins.
  949.         // The default version of this routine sets the margins so that theInterior == theInk
  950.         
  951.     virtual void PrinterChanged();
  952.         // After printer specifications have changed, absorb the new metrics and reformat
  953.         // the view if necessary
  954.  
  955.     virtual void RedoPageBreaks();
  956.         // Recalculate the page breaks
  957.  
  958.     virtual void Reset();
  959.         // Reset print record to default
  960.  
  961.     virtual TPrintInfo* GetPrintInfo();
  962.         // Returns the printinfo (fPrintInfo)
  963.  
  964.     virtual void SetDefaultPrintInfo();
  965.         // Create a PrintInfo record and initialize it to default values
  966.  
  967.     virtual void SetPrintExtent();
  968.         // Sets the part of the print handler's view that is printed by this print
  969.         // handler, by calling the view's GetPrintExtent.
  970.  
  971.     virtual void SetMargins();
  972.         // Install the desired page margins
  973.  
  974.     virtual void DoUpdate(ChangeID theChange,
  975.                   TObject* changedObject,
  976.                   TObject* changedBy,
  977.                   TDependencySpace* dependencySpace);
  978.         // If the printer/printInfo has changed then we're invalid
  979.  
  980.     //------------------------------------------------------------------------------------
  981.     // Scripting Support
  982.     //------------------------------------------------------------------------------------
  983.  
  984.     virtual Boolean DoScriptCommand(CommandNumber aCommandNumber,
  985.                                     TAppleEvent* message,
  986.                                     TAppleEvent* reply);     // override
  987.         // Handle the print apple event
  988.  
  989.     //------------------------------------------------------------------------------------
  990.     // Menu Commands
  991.     //------------------------------------------------------------------------------------
  992.  
  993.     virtual void DoMenuCommand(CommandNumber aCommandNumber);
  994.         // Handles 'show page breaks', among others
  995.  
  996.     virtual Boolean DoPrintCommand(CommandNumber aCommandNumber);
  997.         // called by DoMenuCommand, handles posting the print command, returns true if
  998.         // handled
  999.  
  1000.     virtual void DoSetupMenus();
  1001.         // Sets up menus for 'show page breaks' and company
  1002.  
  1003.     virtual void DoSetupPrintMenus();
  1004.         // called by DoSetupMenus, sets up the print menus
  1005.  
  1006.  
  1007.     //------------------------------------------------------------------------------------
  1008.     // Finder Printing
  1009.     //------------------------------------------------------------------------------------
  1010.     
  1011.     virtual Boolean SetupForFinder(CommandNumber aCommandNumber);
  1012.         // Sets up the print record for finder printing. If fFinderPageSetup is true, then
  1013.         // PosePageSetupDialog is called. If fFinderJobDialog is true, then PoseJobDialog
  1014.         // is called. Otherwise, prJobMerge is called to merge the job record from the
  1015.  
  1016.     virtual Boolean SetupPrintOne(CommandNumber aCommandNumber);
  1017.         // Sets up the print record for a "print one" type of operation, one where the
  1018.         // entire document or view is printed and no job dialog takes place. This is also
  1019.         // used for "drag printing". Returns true if we should proceed.
  1020.  
  1021.  
  1022.     //------------------------------------------------------------------------------------
  1023.     // Screen Feedback
  1024.     //-----------------------------------------------------------------------------------
  1025.  
  1026.     virtual void DrawPrintFeedback(const VRect& area);
  1027.         // Gateway to all screen feedback related to pagination issues
  1028.  
  1029.     virtual void DrawPageBreak(VHSelect vhs,
  1030.                                long whichBreak,
  1031.                                VCoordinate loc,
  1032.                                Boolean automatic);
  1033.         // Draws a page break on the screen.
  1034.  
  1035.     virtual void InvalPageFeedback();
  1036.         // Invalidates all page-related screen feedback
  1037.  
  1038.     virtual Boolean ShowsOnScreen();
  1039.         // Returns true only if the printHandler has an fView which is in an open window.
  1040.  
  1041.  
  1042.     //------------------------------------------------------------------------------------
  1043.     // Dialogs relating to printing
  1044.     //------------------------------------------------------------------------------------
  1045.  
  1046.     virtual Boolean PoseJobDialog();
  1047.         // Pose the 'Print Job' dialog
  1048.  
  1049.     virtual Boolean PosePageSetupDialog(Boolean isUndoable);
  1050.         // Undertake the 'Page Setup' dialog; post a command object to be performed if
  1051.         // relevant. Returns TRUE if the user did not cancel.
  1052.  
  1053.     virtual Boolean ChkPrintErr(OSErr& err,
  1054.                                 Boolean& ranOutOfSpace);
  1055.         // Checks for a MacPrint error, specially handles one particular error (sets
  1056.         // return parameter 'ranOutOfSpace' if error code indicates disk-space problem
  1057.         // while saving a spool file).
  1058.         // Returns TRUE to proceed
  1059.  
  1060.     virtual Boolean PrintSpoolFile(OSErr& err);
  1061.         // If printing was spooled by the print-driver then this method will be called to
  1062.         // print the spooled image.
  1063.         // Returns TRUE to proceed
  1064.  
  1065.     virtual VRect GetPaperRect();
  1066.     
  1067.     virtual VRect GetInkRect();
  1068.     
  1069.     virtual VRect GetMarginsRect();
  1070.     
  1071.     virtual VRect GetInteriorRect();
  1072.  
  1073.     virtual VPoint GetViewPerPage();
  1074.  
  1075.     //----------------------------------------------------------------------------------------
  1076.     // member functions that are really stubs (finally fleshed out here)
  1077.     //----------------------------------------------------------------------------------------
  1078.  
  1079.     virtual void TerminateUPrinting();
  1080.     // Call to terminate the printing system
  1081.  
  1082.     virtual void PrepareForFinderPrinting(const FSSpec* targetPrinter);
  1083.     // call this to prepare for printing from the finder
  1084.     // if targetPrinter is non-NULL then it specifies a "drag print" target
  1085.  
  1086.     virtual void DispatcherIsAvailable();
  1087.     // MacApp calls this when the dispatcher has been created and initialized.
  1088.  
  1089.     virtual long GetSavePrintInfoSize(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
  1090.         // returns the number of bytes necessary to save the print info.
  1091.  
  1092.     virtual void SavePrintInfo(TPrintInfo* itsPrintInfo, TFile* itsFile, Boolean useRsrcFork = TRUE);
  1093.         // Saves the print info to the passed in file.
  1094.  
  1095.     virtual TPrintInfo* RestorePrintInfo(TFile* itsFile, Boolean useRsrcFork = TRUE);
  1096.         // Initializes the print info from the passed in file.
  1097.  
  1098.     //------------------------------------------------------------------------------------
  1099.     // data members
  1100.     //------------------------------------------------------------------------------------
  1101. public:
  1102.     VRect fPrintExtent;                            // the part of the view's extent that is
  1103.                                                 // to be printed by this print handler.
  1104.                                                 // The default is the entire extent, but
  1105.                                                 // it can be changed with the method
  1106.                                                 // SetAreaToPrint.
  1107.  
  1108.     VRect fViewedRect;                            // The part of the view shown on the
  1109.                                                 // "current" page. Set by SetPage.
  1110.  
  1111.     VPoint fViewToQDOffset;                        // the computed translation of coordinates
  1112.                                                 // necessary to account for adjustment of large
  1113.                                                 // views down to QD space. This is set in
  1114.                                                 // FocusOnInterior.
  1115.                                                 
  1116.     VPoint fPageStrips;                            // For printing a view which will take
  1117.                                                 // more than one page to print, the view
  1118.                                                 // is thought of as being divided up by
  1119.                                                 // vertical and horizontal lines ('page
  1120.                                                 // breaks') into a checkerboard of
  1121.                                                 // 'pages'. A vertical column, one page
  1122.                                                 // wide, of such pages is called a
  1123.                                                 // 'vertical page strip', while a
  1124.                                                 // horizontal row, one page high, of such
  1125.                                                 // pages is called a 'horizontal page
  1126.                                                 // strip'. The number of vertical page
  1127.                                                 // strips is represented by fPageStrips.v,
  1128.                                                 // and the number of horizontal page
  1129.                                                 // strips is represented by fPageStrips.h
  1130.                                                 // In a typical Word Processor
  1131.                                                 // application, there is only one vertical
  1132.                                                 // strip of pages, but many horizontal
  1133.                                                 // 'strips', each one only one page wide.
  1134.                                                 // In a graphical application, there may
  1135.                                                 // be many vertical as well as horizontal
  1136.                                                 // strips of pages. fPageStrips is
  1137.                                                 // recomputed by method CalcPageStrips.
  1138.  
  1139.     VPoint fLastStrip;                            // The last strip printed.
  1140.  
  1141.     VPoint fLastBreak;                            // The coordinates of the last page break.
  1142.  
  1143.     CRect fQDRectToClipTo;                        // This the clip rectangle calculated in
  1144.                                                 // FocusOnInterior and FocusOnBorder.  We
  1145.                                                 // use it in ::Focus when a view or subview
  1146.                                                 // being printed needs to focus on its
  1147.                                                 // superview.
  1148.  
  1149.     CPoint fQDOrigin;                            // the computed QD origin for the port to
  1150.                                                 // account for the area being printed.
  1151.                                                 // This is set in FocusOnInterior and
  1152.                                                 // FocusOnBorder.
  1153.                                                 
  1154.     TPrintInfo* fPrintInfo;                        // The print record encapsulated in an object
  1155.                                                 // The Print Record may be shared among all
  1156.                                                 // PrintHandlers in a document or may be
  1157.                                                 // unique to each PrintHandler, depending on
  1158.                                                 // the flag TDocument::fSharePrintInfo
  1159.  
  1160.     CommandNumber fPrintingCommand;                // The command number that was used when
  1161.                                                 // invoking some printing function.  This
  1162.                                                 // can be used to determine if we are
  1163.                                                 // printing from the finder.
  1164.  
  1165.     long fStartPage;                            // the page number for the topleftmost
  1166.                                                 // corner of the view. Normally 1, but can
  1167.                                                 // be set to any positive value
  1168.  
  1169.     VHSelect fPageDirection;                    // Determines how page numbers are to
  1170.                                                 // advance in a large view which is more
  1171.                                                 // than one page wide and more than one
  1172.                                                 // page high; v means page 2 is BELOW page
  1173.                                                 // 1; h means it's to its RIGHT.
  1174.                                                 // Irrelevant if the view is only one page
  1175.                                                 // wide or only one page high
  1176.  
  1177.     Boolean fFixedSizePages[2];                    // Indicates whether pages are fixed size
  1178.                                                 // horizontally and vertically.
  1179.  
  1180.     Boolean fFinderSetup;                        // whether, during Finder Printing, the
  1181.                                                 // 'Page Setup' dialog should be presented
  1182.                                                 // to the user
  1183.  
  1184.     Boolean fFinderJobDialog;                    // whether, during Finder Printing, the
  1185.                                                 // Print Job dialog should be presented to
  1186.                                                 // the user (making it seem like Print...)
  1187.                                                 // or not (making it seem like Print One)
  1188.  
  1189.     Boolean fMinimalMargins;                    // If true, page margins are maintained
  1190.                                                 // such that exactly the complete
  1191.                                                 // printable area of the page is used.
  1192.  
  1193.     Boolean fUseMaxResolution;                    // If true the printing device will be set to
  1194.                                                 // the maximum resolution available.
  1195. protected:
  1196.     //
  1197.     // Former PageAreas struct: metrics for printing
  1198.     //
  1199.     VRect fPaperRect;                            // physical page
  1200.     VRect fInkRect;                                // printable page
  1201.     VRect fMarginsRect;                            // top-left positive; bottom-right negative
  1202.     VRect fInteriorRect;                        // VRect into which view-subset is projected
  1203.  
  1204.  
  1205.     //
  1206.     // Other stuff
  1207.     //
  1208.     Boolean fIsValid;                            // TRUE if the current printer projection
  1209.                                                 // is valid. Set to false when any component
  1210.                                                 // of the calculation of the projection changes.
  1211. };
  1212.  
  1213. //----------------------------------------------------------------------------------------
  1214. // TPrintCommand: Returned in response to a printing request. Doesn't actually do the
  1215. // printing itself, but forwards to the appropriate handler.
  1216. //----------------------------------------------------------------------------------------
  1217.  
  1218. class TPrintCommand : public TCommand
  1219. {
  1220.     MA_DECLARE_CLASS;
  1221.     
  1222. public:
  1223.     TPrintCommand();
  1224.         //Constructor
  1225.     virtual ~TPrintCommand();
  1226.         // Destructor
  1227.         
  1228.     void IPrintCommand(CommandNumber itsCommandNumber,
  1229.                        TStdPrintHandler* itsStdPrintHandler);
  1230.         // Initialize the PrintCommand procedurally
  1231.  
  1232.     virtual void DoIt();
  1233.         // Tell the print handler to print
  1234.  
  1235.     virtual TAppleEvent* MakeAppleEvent();
  1236.  
  1237.     //----------------------------------------------------------------------------------------
  1238.     // data members
  1239.     //----------------------------------------------------------------------------------------
  1240. protected:
  1241.     TStdPrintHandler* fStdPrintHandler;            // the associated print handler
  1242.  
  1243. };
  1244.  
  1245.  
  1246. //----------------------------------------------------------------------------------------
  1247. // TPrintStyleChangeCommand: Used to allow changes made by the user in the 'Page Setup...'
  1248. // dialog to be undoable.
  1249. //----------------------------------------------------------------------------------------
  1250.  
  1251. class TPrintStyleChangeCommand : public TCommand
  1252. {
  1253.     MA_DECLARE_CLASS;
  1254.     
  1255. public:
  1256.     //------------------------------------------------------------------------------------
  1257.     // Initialization and Termination
  1258.     //------------------------------------------------------------------------------------
  1259.  
  1260.     TPrintStyleChangeCommand();
  1261.         // Constructor
  1262.         
  1263.     void IPrintStyleChangeCommand(TStdPrintHandler* itsPrintHandler, Boolean isUndoable = TRUE);
  1264.         // Initializes the print style change command, makes a copy of the old print
  1265.         // handle and creates the new one.
  1266.         // Can be undone if isUndoable is true
  1267.  
  1268.     virtual ~TPrintStyleChangeCommand();
  1269.         // Disposes the old and new print handles.
  1270.  
  1271.     //------------------------------------------------------------------------------------
  1272.     // Command Execution
  1273.     //------------------------------------------------------------------------------------
  1274.  
  1275.     virtual void DoIt();
  1276.         // Sets the print handler's printinfo from the new printinfo.
  1277.  
  1278.     virtual void UndoIt();
  1279.         // Sets the print handler's printinfo from the old printinfo.
  1280.  
  1281.     virtual void SetupDependencies(); // Override
  1282.         // Overridden to make this command a dependent of its print handler's fView. 
  1283.         // And a dependent of its print handler's fPrintMgr. 
  1284.  
  1285.     virtual void DoUpdate(ChangeID theChange,
  1286.                           TObject* changedObject, 
  1287.                           TObject* changedBy,
  1288.                           TDependencySpace* dependencySpace); // Override
  1289.         // If the print handler's fView is closed, commit this command  
  1290.         // If the printer driver has changed behind our back, we can no longer be undone.
  1291.  
  1292.     //----------------------------------------------------------------------------------------
  1293.     // data members
  1294.     //----------------------------------------------------------------------------------------
  1295. protected:
  1296.     TStdPrintHandler* fStdPrintHandler;            // Associated print handler.
  1297.  
  1298.     TPrintInfo* fOldPrintInfo;                    // The old print record, before the change.
  1299.  
  1300. public:
  1301.     TPrintInfo* fNewPrintInfo;                    // The new print record, after the change.
  1302.  
  1303. };
  1304.  
  1305.  
  1306. //----------------------------------------------------------------------------------------
  1307. // Global variable declarations
  1308. //----------------------------------------------------------------------------------------
  1309.  
  1310. extern PenState gBreaksPenState;                // penState to used to draw page breaks
  1311.  
  1312. extern Boolean gCancelAllPrinting;                // set to true if during Finder Printing
  1313.                                                 // user selects Cancel All
  1314.  
  1315. extern VRect gStdPageMargins;                    // "Standard" left, top, right, bottom
  1316.                                                 // page margins, in screen resolution -
  1317.                                                 // one inch all round by default
  1318.  
  1319. extern TPrintInfo* gFinderPrintInfo;            // Used for finder printing, to do
  1320.                                                 // PrJobMerge when printing more than one
  1321.                                                 // document.
  1322.  
  1323. extern TStdPrintHandler* gJobPrintHandler;        // The Print Handler in use during
  1324.                                                 // printing.
  1325.  
  1326. extern TPrintInfo* gDefaultPrintInfo;            // The default TPrintInfo used by the
  1327.                                                 // application. Used if no TPrintInfo* is
  1328.                                                 // supplied to IStdPrintHandler
  1329.                                                 // (Usually the case)
  1330.  
  1331. extern FSSpec gTargetPrinter;                    // The current printer target for a "drag print"
  1332. #if qGXPrinting
  1333. extern Boolean gUsingGXPrinting;
  1334. #endif
  1335.     // TRUE if GX Printing has been initialized (when used)
  1336.  
  1337. //----------------------------------------------------------------------------------------
  1338. // Global function declarations
  1339. //----------------------------------------------------------------------------------------
  1340.  
  1341. extern void InitUPrinting();
  1342.     // Call once, at application start-up time. You can interrogate global variable
  1343.     // 'gCouldPrint' at any time to determine whether printing code is actually accessible
  1344.  
  1345. extern TPrintInfo* NewTPrintInfo(Boolean isValid = FALSE);
  1346.     // The default print record is retrieved from itsPrintMgr.
  1347.  
  1348. #endif
  1349.